﻿using System;
using System.Xml.Linq;
using NCMIS.ObjectModel;
using NCMIS.ObjectModel.MetaData;
using NCMIS.Produce;
using NCMIS.Provider;
using NCMIS.AccessControl;
using System.Collections.Generic;

namespace NCMIS.Provider.SampleProvider
{
    public class SampleNavigationProvider : NavigationProviderBase
    {
        public SampleNavigationProvider()
        {
            SampleFactory.Initialize();
        }

        // Methods interacting with the service contract methods
        #region Service Contract Members

        // returns sample descendants
        public override PathedCmisObjectContainer[] GetDescendants(string repositoryId, string folderId, int? depth, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includePathSegment)
        {
            return new PathedCmisObjectContainer[] { SampleFactory.CreatePathedCmisObjectContainer() };
        }

        public override PathedCmisObjectList GetChildren(string repositoryId, string folderId, int? maxItems, int skipCount, string orderBy, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includePathSegment)
        {
            PathedCmisObjectList list = new PathedCmisObjectList();
            try
            {
                list = SampleFactory.GetChildren(folderId);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return list;
            //SampleFactory.CmisObjects.TryGetValue(folderId, out list);
            //SampleFactory.Children.TryGetValue(folderId, out list);
            //children.TryGetValue(folderId, out list);
            //return list;

            //if (folderId.Equals("NcmisFolder"))
            //{
            //    // No children in folder "NcmisFolder"
            //    return null;
            //}
            //return SampleFactory.CreatePathedCmisObjectList();
        }

        // returns a sample folder tree
        public override PathedCmisObjectContainer[] GetFolderTree(string repositoryId, string folderId, int? depth, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includePathSegment)
        {
            return new PathedCmisObjectContainer[] { SampleFactory.CreatePathedCmisObjectContainer() };
        }

        public override CmisObject GetFolderParent(string repositoryId, string folderId, string filter)
        {
            return SampleFactory.CreateCmisObject();
        }

        public override PathedCmisObject[] GetObjectParents(string repositoryId, string objectId, string filter, IncludeRelationships includeRelationships, string renditionFilter, bool includeAllowableActions, bool includeRelativePathSegment)
        {
            return null; //SampleFactory.CreateCmisObjectParents();
        }

        // returns a sample checked out document
        public override CmisObjectList GetCheckedoutDocs(string repositoryId, string folderId, string filter, string orderBy, bool includeAllowableActions, IncludeRelationships includeRelationships, string renditionFilter, int? maxItems, int skipCount)
        {
            //return SampleFactory.CreateCmisObjectList();
            return SampleFactory.CreateCmisCheckedOutObjectList();
        }

        #endregion
    }
}